#!/usr/bin/make -f


include ../profile


ifeq ($(TYPE),Hi3516CV610)
ARCH:=arm
CROSS_COMPILE_PREFIX=arm-v01c02-linux-musleabi-
CROSS_COMPILE_PATH=/opt/linux/x86-arm/arm-v01c02-linux-musleabi-gcc/bin/
CFLAGS += -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4
CFLAGS += -D__Hi3516CV610__ -DUSE_C_PLUS_PLUS_LANGUAGE
CFLAGS += -Werror=implicit-int  -Werror=return-type
CFLAGS+= -D__FAT32__ -I../include
endif


MK=make
CC=$(CROSS_COMPILE_PREFIX)gcc
CXX=$(CROSS_COMPILE_PREFIX)g++
STRIP=$(CROSS_COMPILE_PREFIX)strip
AR=$(CROSS_COMPILE_PREFIX)ar
RM=rm -rfv
INSTALL=install -c -v -m 777

# ifeq ($(DEBUG), true)
# CFLAGS+= -g -ffunction-sections -fdata-sections -DNDEBUG
# else 
# CFLAGS+= -Os -ffunction-sections -fdata-sections -DNDEBUG
# endif


# CFLAGS+= -D_POSIX_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -DMEMWATCH
# CFLAGS+= -Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual -fpermissive
# LDFLAGS+= -lpthread
# INCLUDES+= -I../include
# DFLAGS+= -g -DDEBUG

MPATH=$(shell pwd)
LIBNAME=$(notdir $(MPATH))

KERNELDIR ?= $(MPATH)/../../kernel
PRINT_INC = $(MPATH)/include
EXTRA_CFLAGS += -I $(PRINT_INC)

# ifeq ($(STATIC), true)
# LIBDIR=../lib-static/
# BIN=lib$(LIBNAME).a
# RELEASE_DIR=RELEASE-static
# else 
# LIBDIR=../lib-dony/
# BIN=lib$(LIBNAME).so
# RELEASE_DIR=RELEASE-dony
# endif 

# LIBPATH+= -Llib -L${LIBDIR} 


# DEBUG_DIR=DEBUG-$(ARCH)
# TARGET_DIRS=$(DEBUG_DIR) $(RELEASE_DIR)
# TARGET_DIR_CHECK=$(patsubst %,%/.,$(TARGET_DIRS))

# DEBUG_TARGET=$(DEBUG_DIR)/$(BIN)
# RELEASE_TARGET=$(RELEASE_DIR)/$(BIN)
# TARGETS=$(DEBUG_TARGET) $(RELEASE_TARGET)
# LIB_TARGETS=$(addprefix ${LIBDIR}/, $(DEBUG_TARGET), $(RELEASE_TARGET))

# OBJECTS=$(patsubst %.c, %.o, $(wildcard *.c))
# OBJECTS+=$(patsubst %.cpp, %.o, $(wildcard *.cpp))

.PHONY:debug relase build test modules clean 


# release:$(RELEASE_DIR)/. $(PROTO_TARGET) $(RELEASE_TARGET)
# debug:$(DEBUG_DIR)/. $(PROTO_TARGET) $(DEBUG_TARGET)

# clean:
# 	$(MK)  -C $(KERNELDIR) M=$(PWD) modules_clean

# create default build dirs
# build:
# %/.:
# 	mkdir -m 777 -p $*
	
# $(DEBUG_TARGET):$(addprefix $(DEBUG_DIR)/,$(OBJECTS))
# 	$(MK) -C $(KERNELDIR) M=$(PWD)  modules
# #	$(INSTALL) $(LIBNAME)_api.h ../include/
# 	$(INSTALL) $@ ../lib_${TYPE}/
	
# ifeq ($(STATIC), true)
# $(RELEASE_TARGET):$(addprefix $(RELEASE_DIR)/,$(OBJECTS))
# 	@$(AR) crD $@ $^
# 	$(INSTALL) $@ ${LIBDIR} 
# #	$(INSTALL) $@ ${FS_LIBDIR}
# else
# $(RELEASE_TARGET):$(addprefix $(RELEASE_DIR)/,$(OBJECTS))
# 	$(MK) -shared  -C $(KERNELDIR) M=$(PWD) modules
# 	$(STRIP) $@
# 	$(INSTALL) $@ ${LIBDIR}
# #	$(INSTALL) $@ ${FS_LIBDIR}
# endif

modules:
	$(MK)  -C $(KERNELDIR) M=$(PWD) modules

#$(DEBUG_DIR)/%.o:%.cpp
#	$(CXX) -c $^ -o $@ $(CFLAGS) $(INCLUDES) $(DFLAGS)
#
#$(RELEASE_DIR)/%.o:%.cpp
#	$(CXX) -c $^ -o $@ $(CFLAGS) $(INCLUDES)
#